package com.huiquan.icd.controller;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.huiquan.analysis.domain.User;
import com.huiquan.framework.base.ReturnData;
import com.huiquan.framework.utils.RequestParamUtil;
import com.huiquan.icd.service.IcdDiseaseIndexService;

@Controller
public class IcdDiseaseIndexController {

	@Autowired
	private IcdDiseaseIndexService icdDiseaseIndexService;

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/icd/disease_index_list.htm")
	public ModelAndView list(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		req.getSession().setAttribute("pstart", RequestParamUtil.getIntegerDefault1LargeThan1(req, "start"));
		req.getSession().setAttribute("pstatus", RequestParamUtil.getIntegerDefaultDi(req, "status", 0));
		req.getSession().setAttribute("pnameSearch", req.getParameter("nameSearch"));
		req.getSession().setAttribute("pcategorySearch", req.getParameter("categorySearch"));
		req.getSession().setAttribute("pexactSearchFlag", req.getParameter("exactSearchFlag"));

		String name = req.getParameter("name");

		Map<String, Object> pageParam = (Map<String, Object>) req.getSession().getAttribute("pageParam");
		pageParam.put("tabid", "25_9");
		req.getSession().setAttribute("pageParam", pageParam);

		return icdDiseaseIndexService.list(name);
	}

	@ResponseBody
	@RequestMapping(value = "/icd/disease_index_check_flag.do")
	public ReturnData checkFlag(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		User user = (User) req.getSession().getAttribute("user");
		String id = RequestParamUtil.getTrimString(req, "id");
		String flag = RequestParamUtil.getTrimString(req, "flag");

		return icdDiseaseIndexService.checkFlag(id, flag, user);
	}

	@ResponseBody
	@RequestMapping(value = "/icd/disease_index_search_list.do")
	public ReturnData searchList(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		User user = (User) req.getSession().getAttribute("user");
		String name = RequestParamUtil.getTrimString(req, "name");
		String indexName = RequestParamUtil.getTrimString(req, "indexNameKey");

		return icdDiseaseIndexService.searchList(name, indexName, user);
	}

	@ResponseBody
	@RequestMapping(value = "/icd/disease_inspection_submit_server.do")
	public ReturnData submitServer(HttpServletRequest req, HttpServletResponse resp) throws Exception {

		return icdDiseaseIndexService.submitServer();
	}

}
